﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using KPIS.GERP.GHRMS.APP.Classes;
using Telerik.Web.UI;
using KPIS.GERP.GHRMS.BLL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.MODEL;

namespace KPIS.GERP.GHRMS.APP.App_UI.UserControls
{
    public partial class PS_HisSpouses : System.Web.UI.UserControl
    {
        private IHisSpouseBLL spouBLL = new HisSpouseBLL();
		private Main main = new Main();
        private RadComboBox cmbPrefixes;
        private object _dataItem = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            cmbPrefixes = (RadComboBox)cbPrefixes.FindControl("cbPrefixes");
            lblEmpSeq.Text = Session["emp_seq"].ToString();
           
            if (DataItem != null)
            {
                cbPrefixes.ListPrefixesComboBox();

                if (!(DataItem is Telerik.Web.UI.GridInsertionObject))
                {                   
                    //DataTable dt =  spouBLL.ListHisSpousesDataTable(lblEmpSeq.Text);
                    //foreach (DataRow dtRow in dt.Rows){
                    //    foreach (DataColumn column in dt.Columns)
                    //   {
                    //      var field1 = dtRow[column].ToString();
                    //   }
                         
                    //}

                    lblSequence.Text = DataBinder.Eval(DataItem, "spouse_seq").ToString();
                    cmbPrefixes.SelectedValue = DataBinder.Eval(DataItem, "NAME_PREFIX_SEQ").ToString();
                    txtName.Text = DataBinder.Eval(DataItem, "spouse_name").ToString();
                    txtLastName.Text = DataBinder.Eval(DataItem, "spouse_last_name").ToString();
                    txtCitizen.Text = DataBinder.Eval(DataItem, "Citizen").ToString();
                    txtPlaceOfBirth.Text = DataBinder.Eval(DataItem, "place_of_birth").ToString();
                    //chkEarning.Checked = true;//
                    var status = DataBinder.Eval(DataItem, "earning_status");
                    if (status != null)
                    {
                        if (status.ToString() == "0") chkEarning.Checked = false;
                        else chkEarning.Checked = true;
                    }
                    cmbStatus.SelectedValue = DataBinder.Eval(DataItem, "SPOUSE_STATUS").ToString();
                }
            }
        }

        public object DataItem
        {
            get
            {
                return this._dataItem;
            }
            set
            {
                this._dataItem = value;
            }
        }

       

        protected void btnAddnew_Click(object sender, EventArgs e)
        {
            spouBLL.Insert(lblEmpSeq.Text.Trim()
                , cmbPrefixes.SelectedValue
                , txtName.Text.Trim()
                , txtLastName.Text.Trim()
                , chkEarning.Checked
                , cmbStatus.SelectedValue
                , txtCitizen.Text.Trim()
                , txtPlaceOfBirth.Text
				, 1);
			main.MessageAlert(Page, "บันทึกข้อมูลแล้ว");
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            spouBLL.Update(Int32.Parse(lblSequence.Text.Trim())
                , lblEmpSeq.Text.Trim()
                , cmbPrefixes.SelectedValue
                , txtName.Text.Trim()
                , txtLastName.Text.Trim()
                , chkEarning.Checked
                , cmbStatus.SelectedValue
                , txtCitizen.Text.Trim()
                , txtPlaceOfBirth.Text
				, 1);
			main.MessageAlert(Page, "บันทึกข้อมูลแล้ว");
        }
    }
}